/**
	重新编辑
*/
var exam;
var examId;
var active;
var repeatFrom;
var repeatTo;
var playMode;
var repeatTime;

var ppt = new PPT();

//洗涤槽
var sink;

$(document).ready(function(){
	var url = window.location.href;
	sink = $(".sink");
	if(url.indexOf("=")!=-1){
		examId = parseInt(url.split("=")[1]);
		getExamInfo(examId);
	}
	else{
		window.close();
	}
});


/**
 * 得到该项目的总体信息 exam
 * @param id
 */
function getExamInfo(id){
	$.ajax({
		url : "../ppt/getExamInfo.html",
		data : "examId=" + id,
		type : 'post',
		dataType : 'json',
		contentType : "application/x-www-form-urlencoded;charset=utf-8",
		success : function(result) {
			if (result != null) {
				exam = result;
				returnId = id;
				
				active = exam.active;
				repeatFrom = exam.repeatFrom;
				repeatTo = exam.repeatTo;
				playMode = exam.playMode.toString();
				repeatTime = exam.repeatTime;
				
				initDataOnPage();
				
				//项目信息正确，取得单元数据
				prepareData();
			} else {
				exam = null;
				alert("获取失败 ");
			}
		},
		error : function() {
			exam = null;
			alert("连接服务器出错  或者  请重新登入");
		}
	});
}

/**
 * 做题前先准备下载数据并提醒
 */
function prepareData(){
	//弹出数据加载中的提示
	$.ajax({
		url : "../ppt/getPPT.html",
		data : "examId=" + examId,
		type : 'post',
		dataType : 'json',
		contentType : "application/x-www-form-urlencoded;charset=utf-8",
		success : function(result) {
			if (result != null && result!=undefined) {
				for(var i=0;i<result.length;i++){
					var cellContent = result[i].htmlContent;
					ppt.addNew();
					ppt.contentA[i] = cellContent;
				}
				//alert(ppt.contentA[0]);
				$(".c-content").html(ppt.contentA[0]);
				ppt.curNO=0;
				ppt.show(0);
				
				introduction = $(".textarea-intr").text();
			} 
			else {
				alert("下载数据出错");
			}
		},
		error : function() {
			alert("连接服务器出错 或者  请重新登入");
		}
	});
}


/**
 * 恢复项目信息<br>
 * 标题<br>
 * 跳转信息
 */
function initDataOnPage(){
	$("#title").val(exam.title);
	
	$("#repeat-info").attr("repeat-from",repeatFrom);
	$("#repeat-info").attr("repeat-to",repeatTo);
	$("#repeat-info").attr("repeat-method",playMode);
	$("#repeat-info").attr("repeat-times",repeatTime);
	
	$("#jump-on-web").attr("checked",active);
	$("#ppt-repeat-from").val(repeatFrom);
	$("#ppt-repeat-to").val(repeatTo);
	$("#ppt-repeat-method").val(playMode);
	$("#ppt-repeat-times").val(repeatTime);
	
	if(active==true){
		$("#repeat-info").attr("active","on");
		$("#ppt-repeat-span select").attr("disabled",false);
		$("#ppt-repeat-times").attr("disabled",false);
		$("#when-condition").attr("disabled",true);
		$("#jump-to").attr("disabled",true);
	}
}

